package com.roadrunner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

class StableArrayAdapter extends ArrayAdapter<String> 
{
	private final Context m_context;
	private final ArrayList<Job> m_orders;
	  
    public StableArrayAdapter(Context context, int textViewResourceId, List<String> orderAdresses, ArrayList<Job> orders)
    {
    	super(context, textViewResourceId, orderAdresses);
    	
    	m_context 	= context;
    	m_orders 	= orders;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    	LayoutInflater inflater = (LayoutInflater) m_context
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    	View rowView = inflater.inflate(R.layout.order_row, parent, false);
      
    	TextView textView = (TextView) rowView.findViewById(R.id.orderAddress);
    	ImageView imageView = (ImageView) rowView.findViewById(R.id.statusImage);
      
    	String textAddress = new String();
    	
    	if(m_orders.get(position).getJobState().compareTo("PICKED_UP") == 0)
    	{
    		textAddress = m_orders.get(position).getDestAdress();
    		imageView.setImageResource(R.drawable.drop);
    	}
		else
		{
			textAddress = m_orders.get(position).getExpAdress();
			imageView.setImageResource(R.drawable.pickup);
		}
    	
    	textView.setText(textAddress);
    	return rowView;
    }
}
